package com.hhit.bigscreenbackmanage.service.impl.jsgl;

import com.alibaba.fastjson.JSONObject;
import com.hhit.bigscreenbackmanage.dao.jsgl.TJsglGljhMapper;
import com.hhit.bigscreenbackmanage.entity.jsgl.TJsglGljh;
import com.hhit.bigscreenbackmanage.service.jsgl.TJsglGljhService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TJsglGljhServiceImpl implements TJsglGljhService {

    private Logger log = LoggerFactory.getLogger(TJsglGljhServiceImpl.class);

    @Autowired
    TJsglGljhMapper tJsglGljhMapper;

    @Override
    public void importGljh(TJsglGljh tJsglGljh) throws Exception {
        if(tJsglGljh.getTitle() == null || "".equals(tJsglGljh.getTitle())){
            throw new Exception("缺少必要参数: title");
        }
        if(tJsglGljh.getDataTime() == null || "".equals(tJsglGljh.getDataTime())){
            throw new Exception("缺少必要参数: dataTime");
        }

        try {
            tJsglGljhMapper.insertGljh(tJsglGljh);
        }catch (Exception e){
            log.error(e.getMessage());
            throw new Exception("数据库内部异常");
        }
    }

    @Override
    public List<TJsglGljh> queryGljh(JSONObject jsonObject) throws Exception {
        if(jsonObject.get("dataTime") == null || "".equals(jsonObject.get("dataTime"))){
            throw new Exception("缺少必要参数: dataTime");
        }

        List<TJsglGljh> result = new ArrayList<>();
        try{
            result = tJsglGljhMapper.queryGljh(jsonObject);
        }catch (Exception e){
            log.error(e.getMessage());
            throw new Exception("数据内部错误");
        }

        return result;
    }
}
